/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Cadastro_usuarios.java
 *
 * Created on 07/06/2011, 19:24:27
 */

package Interface;

import Core.*;
import Utilitarios.conexao;
import javax.swing.JOptionPane;

/**
 *
 * @author Ramon
 */
public class Cadastro_disciplinas extends javax.swing.JFrame {

    conexao banco=new conexao();
    /** Creates new form Cadastro_usuarios */
    public Cadastro_disciplinas() {
        initComponents();

        banco.conecta();

        try
        {
            
            banco.executeSQL("select * from discipline ");
            

        }catch(Exception error){JOptionPane.showMessageDialog(null, error);}


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        JT_nome = new javax.swing.JTextField();
        JC_sem = new javax.swing.JComboBox();
        JC_ano = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        JC_cred = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        JT_hora_aula = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        JC_prof = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        JL_freq_sem = new javax.swing.JLabel();
        JC_freq_sem = new javax.swing.JComboBox();
        JL_cod = new javax.swing.JLabel();
        JT_cod_disc = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Disiciplinas");
        setBackground(new java.awt.Color(255, 255, 255));
        setName("TEC-IHC"); // NOI18N

        jLabel1.setText("Nome.:");

        jLabel2.setText("Semestre.:");

        JC_sem.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02" }));

        JC_ano.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2011", "2012", "2013", "2014", "2015", "2016" }));

        jLabel4.setText("Creditos.:");

        JC_cred.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "02", "04", "06", "10", "12", "14", "16", "20", "22", "24", "26", "28", "30" }));
        JC_cred.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JC_credMouseClicked(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                JC_credMouseExited(evt);
            }
        });
        JC_cred.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JC_credActionPerformed(evt);
            }
        });

        jLabel5.setText("/");

        jLabel6.setText("Horas de aula.:");

        JT_hora_aula.setEditable(false);
        JT_hora_aula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JT_hora_aulaActionPerformed(evt);
            }
        });

        jLabel7.setText("Professor.:");

        JC_prof.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JC_profActionPerformed(evt);
            }
        });

        jButton2.setText("Salvar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Limpar Campos");

        JL_freq_sem.setText("Frequencia Semanal.:");

        JC_freq_sem.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06" }));

        JL_cod.setText("Código.:");

        JT_hora_aula.setEditable(false);
        JT_cod_disc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JT_cod_discActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(22, 22, 22))
                            .addComponent(jLabel7)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(JT_nome)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(JC_sem, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(16, 16, 16)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(JC_ano, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(JC_cred, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(JC_prof, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(JT_cod_disc, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(JT_hora_aula, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JL_freq_sem)
                        .addGap(18, 18, 18)
                        .addComponent(JC_freq_sem, 0, 80, Short.MAX_VALUE)))
                .addGap(25, 25, 25))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(244, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addGap(66, 66, 66))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(JL_cod)
                .addContainerGap(408, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(JT_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(JC_sem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(JC_ano, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5)
                        .addComponent(jLabel4)
                        .addComponent(JC_cred, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JC_prof, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JT_hora_aula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(JL_freq_sem)
                    .addComponent(JC_freq_sem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_cod)
                    .addComponent(JT_cod_disc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton2)))
        );

        setBounds(500, 200, 476, 281);
    }// </editor-fold>

    private void JT_hora_aulaActionPerformed(java.awt.event.ActionEvent evt) {                                             


        // TODO add your handling code here:
    }                                            

    private void jC_creditoMouseClicked(java.awt.event.MouseEvent evt) {                                        

        int creditos=0;
        creditos=Integer.parseInt((String)JC_cred.getSelectedItem())*15;

        JT_hora_aula.setText(""+creditos);

    }                                       

    private void jC_creditoMouseExited(java.awt.event.MouseEvent evt) {                                       






    }                                      

    private void jC_creditoActionPerformed(java.awt.event.ActionEvent evt) {                                           


        
    }                                          

    private void jC_professorActionPerformed(java.awt.event.ActionEvent evt) {                                             
  

        // TODO add your handling code here:
    }                                            

    private void jB_salvarActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:

        if ( JT_nome.getText().equals("")==true )
                JOptionPane.showMessageDialog(null," Você deixou algum dos campos em branco");//Caixa de dialogo
           
        else
        {
         Disciplina disciplina = new Disciplina();

         disciplina.setNome(JT_nome.getText());
         disciplina.setCredito(Integer.parseInt(JC_cred.getSelectedItem().toString()));
         disciplina.setSemestre((String)JC_sem.getSelectedItem()+"/"+JC_ano.getSelectedItem());
         disciplina.setCodigo(JT_cod_disc.getText());
         disciplina.setFreq_semanal(Integer.parseInt((String)JC_freq_sem.getSelectedItem()));
         disciplina.setQtd_hr_aula(Integer.parseInt(JT_hora_aula.getText()));

        
        }

        try
        {
            banco.conecta();
            banco.statement.executeUpdate("insert discipline(\"iDdiscipline\",halfyear,dis_name,dis_credits,workload,id_user,");

            //INSERT INTO discipline("iDdiscipline", halfyear, dis_name, dis_credits, workload, id_user, "idPlan")VALUES (?, ?, ?, ?, ?, ?, ?);
            
        }catch (Exception error){JOptionPane.showMessageDialog(null, error);}

    }                                         

    private void jT_codigoActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
    }                                         

    private void jT_frequenciaSemanalActionPerformed(java.awt.event.ActionEvent evt) {                                                     
        // TODO add your handling code here:
        
    }                                                    

    private void JT_qtd_hora_aulaActionPerformed(java.awt.event.ActionEvent evt) {                                                 
        // TODO add your handling code here:
    }                                                

    private void jB_limparActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        JT_nome.setText("");
        JT_cod_disc.setText("");
    }                                         

    private void jB_pesquisarActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
    }                                            

    private void JT_pesquisarActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
    }                                            

    private void JT_cod_discActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

      try
      {
          
      }

    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Cadastro_disciplinas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JComboBox JC_ano;
    private javax.swing.JComboBox JC_cred;
    private javax.swing.JComboBox JC_freq_sem;
    private javax.swing.JComboBox JC_prof;
    private javax.swing.JComboBox JC_sem;
    private javax.swing.JLabel JL_cod;
    private javax.swing.JLabel JL_freq_sem;
    private javax.swing.JTextField JT_cod_disc;
    private javax.swing.JTextField JT_hora_aula;
    private javax.swing.JTextField JT_nome;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    // End of variables declaration

}
